package com.storydo.thread.pool;

import java.time.Duration;

import lombok.Data;

/**
 *
 * @author story
 *
 * 处理应用启动时的参数信息
 */

@Data
public class Argument {

	private Integer threadCount = 2;
	
	// 起始值
	private Long start = 0l;
	
	// 最大任务参数
	private Long nMax = 5l;
	
	// 数据输出文件路径
	private String output = "output";
	
	private String input;
	
	//执行程序
	private String program;
	
	//结果求和,结果须为数字类型
	private Boolean needSum = false;
	
	// 超时时间
	private Duration timeout = Duration.parse("P300D");
	
	// 使用程序输出流 | 返回值 两种类型作为输出结果
	private String result = "outputstream";
	
	/**
	 * 解析输入参数
	 * @param args
	 * @return
	 */
	public static Argument parse(String[] args) {
		Argument result = new Argument();
		for (String str : args) {
			String[] split = str.split("=");
			switch (split[0]) {
			case "--start":
				result.setStart(Long.valueOf(split[1]));
				break;
			case "--n":
				result.setNMax(Long.valueOf(split[1]));
				break;
			case "--threadCount":
				result.setThreadCount(Integer.valueOf(split[1]));
				break;
			case "--output":
				result.setOutput(split[1]);
				break;
			case "--program":
				result.setProgram(split[1]);
				break;
			case "--timeout":
				result.setTimeout(Duration.parse(split[1]));
				break;
			case "--sum":
				result.setNeedSum(true);
				break;
			default:
				break;
			}
		}
		return result;
	}
}
